package capricornus.components.button
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;

	[Event(name="change", type="flash.events.Event")]
	public class CheckBox extends Button
	{
		private var _selectIcon:DisplayObject;
		
		public function CheckBox()
		{
			super();
			init();
		}
		
		override protected function setSkinClass():void
		{
			_disabledSkinClass = CheckBox_disabledIcon;
			_upSkinClass = CheckBox_upIcon;
			_overSkinClass = CheckBox_overIcon;
			_downSkinClass = CheckBox_downIcon;
		}
		
		private function init():void
		{
			_selectIcon = new selectClass() as DisplayObject;
			_selectIcon.visible = false;
			_selectIcon.x = (_currentSkin.width - _selectIcon.width)>>1;
			_selectIcon.y = (_currentSkin.height - _selectIcon.height)>>1;
			_container.addChild( _selectIcon );
		}
		
		protected function get selectClass():Class
		{
			return CheckBox_selectedIcon;
		}
		
		/**
		 * CheckBox不能设置大小 
		 * @param w
		 * @param h
		 * 
		 */		
		override public function setSize(w:int, h:int):void
		{
			
		}
		
		override public function set selected(value:Boolean):void
		{
			var ls:Boolean = super.selected;
			
			super.selected = value;
			_selectIcon.visible = value;
			
			if( ls != value )
			{
				dispatchEvent( new Event( Event.CHANGE ) );
			}
		}
		
		override protected function onMouseDown(e:MouseEvent):void
		{
			selected = !selected;
		}
		
		override protected function onMouseOut(e:MouseEvent):void
		{
			if( !selected ) super.onMouseOut(e);
		}
		
		override protected function onMouseOver(e:MouseEvent):void
		{
			if( !selected ) super.onMouseOver(e);
		}
		
		override protected function onMouseUp(e:MouseEvent):void
		{
			if( !selected ) super.onMouseUp(e);
		}
		
		override protected function resetLabel():void
		{
			if( _label )
			{
				_label.x = _currentSkin.width + 2;
				_label.y = (_currentSkin.height - _label.height)>>1;
			}
		}
	}
}